<?php 
	namespace Index\Controller;
	use Think\Controller;
/**
 * 登录控制器
 */
//相当是父亲
	class LoginController extends CommonController {

		public function index()
		{	
			// $abd=" select face,nickname,title from  user a left join question b on a.id=b.uid              ";
			// $tt=M()->query($abd);
			// var_dump($tt);
				//layout(false);
			if (isset($_SESSION['uid'])) {
				$this->success('你已登录', U('index/user/index'));
			}
			$question=D('vercode')->getOne();
	    	$this->assign('question',$question);
	    	//登陆说明
	    	$this->assign('title',"登陆");
	       $this->display();
		}
		public function log()
		{
			D('vercode')->checkCode(I('post.vercode'));

			$email = I('post.email');

    	    $password = md5(I('post.pass'));

    		$res = M('user')->where("email='$email' and password='$password'")->find();
			if ($res) {
				
				//后台管理封号
				if ($res['status']==1) {
                Reajax(1,"你已被管理停用,请与管理员联系");
            	}

				$_SESSION['nickname']=$res['nickname'];
				$_SESSION['uid']=$res['id'];
				if ($res['face']) {
					$_SESSION['face']=__ROOT__.$res['face'];
				}else{
					$_SESSION['face']=$res['qqface'];
				}
				// $_SESSION['city']=$res['city'];
				// $_SESSION['sign']=$res['sign'];
				Reajax(0,登录成功);
			}else{
				Reajax(1,"登录密码或邮箱错误");
			}
		}

		public function out()
		{
			session_unset();
			session_destroy();
			$this->success("退出成功",U("index/index/index"));
		}
//	<----------------------------------------QQ关联--------------------------------------------->	
    	//qq登录
		public function qqlogin()
		{
			qqlogin();

		}
		//qq返回来的
		public function qqreturn()
		{
			$openid=getOpenId();
			// var_dump($openid);
			$res=M('user')->where("openid='$openid'")->find();
			if ($res) {
				$_SESSION['nickname']=$res['nickname'];
				$_SESSION['uid']=$res['id'];
				if ($res['face']) {
					$_SESSION['face']=__ROOT__.$res['face'];
				}else{
					$_SESSION['face']=$res['qqface'];
				}
				
				$this->success('登录成功',U('index/user/index'));
			}else{

				$userinfo=getuserinfo();
				var_dump($userinfo);
				$data['openid']=$openid;
				$data['nickname']=$userinfo['nickname'];
				$data['city']=$userinfo['city'];
				$data['qqface']=$userinfo['figureurl_qq_1'];
				$data['face']='';
				$data['sex']=$userinfo['gender'];
				$data['create_time']=time();

				if ($id=M('user')->add($data)) {

					$_SESSION['uid']=$id;
					$_SESSION['nickname']=$data['nickname'];
					$_SESSION['face']=$data['qqface'];
					$this->success('登录成功',U('index/user/index'));

				}
			}

		}
		//接口取一个城市
		public function getcity()
		{
        $ip = "121.33.61.243";

        $url = "http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;

        $data = file_get_contents($url);

        var_dump(json_decode($data,true));

        var_dump($_SERVER);
		}









	};




?>